
module Comparator_Hysteretic
    #(
        parameter iWIDTH=10,
        parameter oWIDTH=32,
        parameter THRESHOLD=32,
        parameter oHIGH=32'h7FFF_FFFF,
        parameter oLOW=32'h8000_0000
    )
    (
        input wire signed [iWIDTH-1:0] i_SignalInput,
        input wire signed [iWIDTH-1:0] i_Reference,
        input wire i_clk,
        input wire i_rst,
        output reg signed [oWIDTH-1:0] o_SignalOutput
    );
    wire signed [oWIDTH-1:0] diff;

    assign diff=({{(oWIDTH-iWIDTH){i_SignalInput[iWIDTH-1]}},i_SignalInput[iWIDTH-1:0]}-{{(oWIDTH-iWIDTH){i_Reference[iWIDTH-1]}},i_Reference[iWIDTH-1:0]});

    always@(posedge i_clk or posedge i_rst) begin
        if(i_rst) begin
            o_SignalOutput<='b0;
        end
        else begin
            if(diff>THRESHOLD) begin
                o_SignalOutput<=oHIGH;
            end
            else if(diff<-THRESHOLD) begin
                o_SignalOutput<=oLOW;
            end
            else begin
                o_SignalOutput<=o_SignalOutput;
            end 
        end
    end

endmodule
